﻿namespace IntellectShop.Common
{
	using System;
	using System.ComponentModel.DataAnnotations;

	public partial class Commodity
	{
		[ScaffoldColumn(false)]
		public int CommodityID { get; set; }

		[DisplayNameLocalized("CommodityCode")]
		[Required(ErrorMessageResourceName = "CodeIsRequired", ErrorMessageResourceType = typeof(Resources.Errors))]
		public string Code { get; set; }

		[DisplayNameLocalized("Name")]
		[Required(ErrorMessage = "Name is required")]
		[StringLength(4000, ErrorMessage = "Name must be less then 4000 characters")]
		public string Name { get; set; }

		public string NamePrint
		{
			get { return ConvertUtils.RemoveSpecialChars(this.Name); }
		}

		[DisplayNameLocalized("Price")]
		[MoneyValidationAttribute(ErrorMessage = "Invalid price")]
		public Money Price { get; set; }

		[DisplayNameLocalized("Description")]
		[StringLength(4000, ErrorMessage = "Description must be less then 4000 characters")]
		public string Description { get; set; }

		[DisplayNameLocalized("SortingID")]
		[Required(ErrorMessageResourceName = "SortingIDIsRequired", ErrorMessageResourceType = typeof(Resources.Errors))]
		public int SortingID { get; set; }

		[DisplayNameLocalized("Tags")]
		public string TagsString
		{
			get { return this.Tags.ToString(); }

			set { this.Tags = new TagsSet(this.CommodityID, value); }
		}

		private TagsSet _tags = null;
		public TagsSet Tags
		{
			get
			{
				if (_tags == null)
				{
					_tags = TagsSet.RetrieveByCommodityID(this.CommodityID);
				}

				return _tags;
			}

			set
			{
				_tags = value;
			}
		}

		[DisplayNameLocalized("Created")]
		public DateTime? Created { get; set; }

		[DisplayNameLocalized("CreatedBy")]
		public string CreatedBy { get; set; }

		[DisplayNameLocalized("Updated")]
		public DateTime? Updated { get; set; }

		[DisplayNameLocalized("UpdatedBy")]
		public string UpdatedBy { get; set; }

		private CommodityType _commodityType = Common.CommodityType.NotSpecified;
		[ScaffoldColumn(false)]
		public virtual CommodityType CommodityType
		{
			get
			{
				return _commodityType;
			}

			set
			{
				_commodityType = value;
			}
		}

		[DisplayNameLocalized("Closed")]
		public DateTime? Closed { get; set; }

		public string Print()
		{
			return String.Format("{0} - {1}", this.Code, this.NamePrint);
		}
	}
}
